package com.greenway.beans.clickstates;

import javax.faces.application.FacesMessage;

import org.primefaces.event.map.PointSelectEvent;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;

import com.greenway.beans.MapBean;

public class StartMarkerState implements State {

	private MapBean mapBean;

	public StartMarkerState(MapBean mapBean) {
		this.mapBean = mapBean;
	}
	
	@Override
	public void handleMarker(PointSelectEvent event, MapModel mapModel) {
		
		LatLng latlng = event.getLatLng(); 
		
		//Create start marker
		Marker markerStart = new Marker(latlng, "start", null,
				"http://localhost:9090/GreenPlanet/images/start.png");
		markerStart.setDraggable(true);
		mapModel.addOverlay(markerStart);		
				
		mapBean.setState(mapBean.getFinishMarkerState());
		
		mapBean.addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Info",
                "Please place end point"));
		
		mapBean.addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO,
				"Point Selected", "Lat:" + latlng.getLat() + ", Lng:"
						+ latlng.getLng()));
	}
	
}
